'''
Created on May 21, 2012

@author: Vu Dao
'''
# Search a article
from selenium import webdriver
from Interface.articleManagerPage import xpathSearchText, xpathSearchButton,\
    xpathArticleCheckBox, xpathPublishButton, xpathArticleTextPublishSul,\
    xpathArticleStatusPublishSul, xpathUnpublishButton,\
    xpathArticleTextUnpublishSul, xpathArticleStatusUnpublishSul,\
    xpathArchivedButton, xpathArticleTextArchivedSul, xpathCheckInButton,\
    xpathCheckinTextArticleSul
from selenium.webdriver.support.wait import WebDriverWait
def searchAArticle(self,articleName):
    browser = self.browser
    # type a article name
    element = browser.find_element_by_xpath(xpathSearchText())
    element.clear()
    element.send_keys(articleName)
    # click on Search button
    element = browser.find_element_by_xpath(xpathSearchButton())
    element.click()
    browser.implicitly_wait(60)
    
# select a article
def selectAArticle(self,articleName):
    browser = self.browser
    element = browser.find_element_by_xpath(xpathArticleCheckBox(articleName))
    element.click()
    
# click on Publish button
def clickOnPublishButton(self):
    browser = self.browser
    element = browser.find_element_by_xpath(xpathPublishButton())
    element.click()
    
# verify publish a article successfully
def verifyPublishArticle(self,articleName):
    browser = self.browser
    try:
        WebDriverWait(browser,20).until(lambda browser: browser.find_element_by_xpath(xpathArticleTextPublishSul()) and browser.find_element_by_xpath(xpathArticleStatusPublishSul(articleName)))
        return True
    except:
        return False
    
# click on Unpublish button
def clickOnUnpublishButton(self):
    browser = self.browser
    element = browser.find_element_by_xpath(xpathUnpublishButton())
    element.click()
    
# verify unpublish a article successfully 
def verifyUnpublishArticle(self,articleName):
    browser = self.browser
    try:
        WebDriverWait(browser,20).until(lambda browser: browser.find_element_by_xpath(xpathArticleTextUnpublishSul()) and browser.find_element_by_xpath(xpathArticleStatusUnpublishSul(articleName)))
        return True
    except:
        return False
    
# click on Archived button
def clickOnArchivedButton(self):
    browser = self.browser
    element = browser.find_element_by_xpath(xpathArchivedButton())
    element.click()
    
# verify archived a article successfully
def verifyArchivedArticle(self):
    browser = self.browser
    try:
        WebDriverWait(browser,20).until(lambda browser: browser.find_element_by_xpath(xpathArticleTextArchivedSul()))
        return True
    except:
        return False

# click on Check-In Button
def clickOnCheckInButton(self):
    browser = self.browser
    element = browser.find_element_by_xpath(xpathCheckInButton())
    element.click()
    
# verify check-In a article successfully
def verifyCheckInArticle(self):
    browser = self.browser
    try:
        WebDriverWait(browser,20).until(lambda browser: browser.find_element_by_xpath(xpathCheckinTextArticleSul()))
        return True
    except:
        return False